import { ElMessage } from 'element-plus';

export default function useClipboard() {
  const copy = async (text, onSuccess) => {
    try {
      await navigator.clipboard.writeText(text);
      ElMessage.success('复制成功');
      if (onSuccess) onSuccess();
    } catch (err) {
      ElMessage.error('复制失败');
      console.error('复制异常', err);
    }
  };

  return { copy };
}
